package regist;

import regist.dto.UserDto;

/**
 * 用户注册操作.
 *
 * @author GongXincheng
 * @since 2019-09-23 15:25
 */
public class Subject_UserRegist extends BaseSubject<UserDto> {

    Subject_UserRegist() {
        this.add(new ObserverEmail(this));
        this.add(new ObserverExper(this));
    }

    /**
     * 用户注册方法.
     */
    public void userRegist() {
        UserDto userDto = new UserDto();
        userDto.setUsername("admin");
        userDto.setEmail("gxc@163.com");
        System.out.println("用户输入的：" + userDto);

        // 设置发布者的状态
        this.setSubjectStatus(userDto);
        // 通知所有订阅了该主题的观察者（订阅者）
        this.doObserver();

        System.out.println("用户注册成功，" + userDto);
    }

    @Override
    void doObserver() {
        this.getObserverList().forEach(BaseObserver::operation);
    }

    @Override
    void add(BaseObserver<UserDto> observer) {
        this.getObserverList().add(observer);
    }

    @Override
    void delete(BaseObserver<UserDto> observer) {
        this.getObserverList().remove(observer);
    }
}
